/*-------- Includes --------*/
#include <stdio.h>
#include <stdbool.h>
#include <string.h>

/*-------- Defines --------*/
#define MAX_TYPE 64

/*-------- Types --------*/
typedef struct {
    int type;
    int num;
    int solu[4];
} stamp_t;

/*-------- Global variables --------*/
int deno[MAX_TYPE + 1] = {0};
int time[MAX_TYPE + 1] = {0};
int den_len            =  0 ;
stamp_t result;
bool hasResult = false;
bool isTie     = false;

/*-------- Function prototypes --------*/
static void sort(int *a, int n);
static void dfs(int need, int type, int num, int pdo, int solu[]);
static void update(stamp_t *p, int type, int num, int solu[]);
static void print(stamp_t *p, int need);

/*-------- Main Function --------*/
int main(int argc, char const *argv[])
{
    int temp;

    while (true) {
        // read denomination of stamps
        if (scanf("%d", &temp) == EOF) break;
        for (den_len = 0; temp != 0; den_len++) {
            deno[den_len] = temp;
            scanf("%d", &temp);
        }

        // sort(deno, den_len);

        while (scanf("%d", &temp) == 1 && temp != 0) {
            // initialize result structure
            int solu[4] = {0};
            update(&result, 0, 0, solu);
            hasResult = false;
            isTie     = false;

            // search the results
            dfs(temp, 0, 0, 0, solu);

            // print the results
            print(&result, temp);
        }
    }

    return 0;
}

/*-------- Functions --------*/
void sort(int *a, int n)
{
    for (int i = 1; i < n; i++) {
        int j;
        int v = a[i];
        for (j = i; j > 0 && a[j-1] > v; j--)
            a[j] = a[j-1];
        a[j] = v;
    }
}

void dfs(int need, int type, int num, int pdo, int solu[])
{
    if (need == 0) {    // find a solution
        if (hasResult) {
            if (type == result.type) {
                if (num == result.num) {
                    if (solu[num - 1] == result.solu[num - 1]) {
                        isTie = true;
                        return;
                    } else if (solu[num - 1] < result.solu[num - 1]) {
                        return;
                    }
                } else if (num > result.num) {
                    return;
                }
            } else if (type < result.type) {
                return;
            }
        }
        // no result, more types, fewer numbers, bigger hval
        update(&result, type, num, solu);
        hasResult = true;
        isTie     = false;
    } else {            // keep moving
        if (num == 4) return;   // maximum of number
        for (int i = pdo; i < den_len; i++) {
            if (deno[i] > need) break;  // reach the bottom

            // update solution
            solu[num] = deno[i];
            time[i]++;
            if (time[i] == 1)
                dfs(need - deno[i], type + 1, num + 1, i, solu);
            else
                dfs(need - deno[i], type, num + 1, i, solu);

            // restore status for backtracing
            time[i]--;
        }
    }
}

void update(stamp_t *p, int type, int num, int solu[])
{
    p->type = type;
    p->num  = num;
    memcpy(p->solu, solu, sizeof(p->solu));
}

void print(stamp_t *p, int need)
{
    if (hasResult) {
        printf("%d (%d): ", need, p->type);
        if (isTie) {
            printf("tie\n");
        } else {
            for (int i = 0; i < p->num; i++)
                printf("%d ", p->solu[i]);
            putchar('\n');
        }
    } else {
        printf("%d ---- none\n", need);
    }
}
